#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int areDistinct(int * arr,int len);

int
main(int argc,char * argv[]){

	// -需要两个参数
	if(2 != argc){
		return EXIT_FAILURE;
	}
	// -根据第二个参数打开文件
	FILE * fptr = fopen(argv[1],"r");
	if(NULL == fptr){
		printf("open file %s failed.\n",argv[1]);
		return EXIT_FAILURE;
	}
	int length = 0;
	int value;
	// -循环读取文件 统计长度
	while(fscanf(fptr,"%d\n",&value) == 1){

		length++;
	}
	printf("get file number length = %d\n",length);
	// -回到文件的开始位置
	fseek(fptr,0,SEEK_SET);
	int * arr = (int*)malloc(length * sizeof(int));
	while(fscanf(fptr,"%d\n",&(arr[length])) == 1){

		length++;
	}
	fclose(fptr);
	// -判断数组里面是否有相同的数值
	int dist = areDistinct(arr,length);
	printf("The elements are");
	if(dist == 0){
	
		printf(" not");
	}
	printf(" distinct.\n");
	free(arr);
	return EXIT_SUCCESS;
}


